//
// Created by 赵江明 on 16/8/11.
//

#import "HttpManager+Out.h"

#import <ReactiveCocoa/ReactiveCocoa.h>

#import "AFHTTPSessionManager+Out.h"
#import "HttpManager.h"


@implementation HttpManager (Out)

- (RACSignal *)getURL:(NSString *)url params:(NSDictionary *)params {
    NSMutableDictionary *dictionary;
    if (params) {
        dictionary = [NSMutableDictionary dictionaryWithDictionary:params];
    } else {
        dictionary = [NSMutableDictionary dictionary];
    }

    return [[[[self get:url parameters:dictionary]
            map:^id(RACTuple *value) {
                return value;
            }] catch:^(NSError *error) {
        return [RACSignal error:error];
    }] replayLazily];
}

- (RACSignal *)postURL:(NSString *)url params:(NSDictionary *)params {
    NSMutableDictionary *dictionary;
    if (params) {
        dictionary = [NSMutableDictionary dictionaryWithDictionary:params];
    } else {
        dictionary = [NSMutableDictionary dictionary];
    }

    return [[[[self post:url parameters:dictionary]
            map:^id(RACTuple *value) {
                return value;
            }] catch:^(NSError *error) {
        return [RACSignal error:error];
    }] replayLazily];
}

@end